// pages/distribut/account_funds/account_funds.js
var app = getApp();
var setting = app.globalData.setting;
var request = app.request;
var common = require('../../../utils/common.js');
import LoadMore from '../../../utils/LoadMore.js'
var load = new LoadMore;
var util = require('../../../utils/util.js');

Page({
	/**
	 * 页面的初始数据
	 */
	data: {
		type: 0,
		url: setting.url,
		leaderInfo: app.globalData.leaderInfo,
		tablist: [],
		currentTab: 1,
		page: 1,
		one: 0,
		two: 0,
		three: 0,
		currentPage: 1,
		list: [],
		leaderInfo: {}
	},

	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad(options) {
		if (options && options.type) {
			this.setData({
				type: options.type
			})
		}
		this.getTablist();
		this.getinfo()
	},
	// 提现
	withdrawal() {
		let that = this
		wx.showModal({
			editable: true, //显示输入框
			placeholderText: '输入金额', //显示输入框提示信息
			type: Number,
			success: res => {
				if (res.confirm) { //点击了确认
					request.post('/api/shop/withdrawal', {
						data: {
							count: res.content
						},
						success: function(res) {
							if (res.data.status == 1) {
								wx.showToast({
									title: '提现申请已提交'
								})
								that.getinfo()
							}
						}
					});
					console.log(res.content) //用户输入的值
				} else {}
			}
		})
	},
	//获取团长端数据
	getinfo() {
		let that = this
		request.get('/api/shop/getShopInfo', {
			success: function(res) {
				if (res.data.status == 1) {
					that.setData({
						leaderInfo: res.data.result
					});
				}
			}
		});
	},
	getTablist: function(type) {
		let that = this
		request.get('/api/shop/getCommissionLog', {
			data: {
				page_no: that.data.currentPage,
				page_size: 10
			},
			success: function(res) {
				if (res.data.status == 1 && res.data.result.data.length != 0) {
					that.data.currentPage++;
					let datalist = that.data.list.concat(res.data.result.data || [])
					if (datalist.length > 0) {
						for (var index in datalist) {
							datalist[index].create_time = util.formatTime(datalist[index]
								.create_time, 'Y/M/D h:m:s');
						}
					}
					that.setData({
						list: datalist,
						currentTab: res.data.result.count
					})
				}

			}
		});
	},
	/**
	 * 生命周期函数--监听页面初次渲染完成
	 */
	onReady() {

	},

	/**
	 * 生命周期函数--监听页面显示
	 */
	onShow() {

	},

	/**
	 * 生命周期函数--监听页面隐藏
	 */
	onHide() {

	},

	/**
	 * 生命周期函数--监听页面卸载
	 */
	onUnload() {

	},

	/**
	 * 页面相关事件处理函数--监听用户下拉动作
	 */
	onPullDownRefresh: function(e) {
		// this.data.points = null;
		// this.data.currentPage = 1;
		// load.resetConfig();
		// this.getTablist(this.data.type);
	},

	/**
	 * 页面上拉触底事件的处理函数
	 */
	onReachBottom: function() {
		if (Math.ceil(this.data.currentTab) > this.data.currentPage) {
			this.getTeamList();
		}
	},

	/**
	 * 用户点击右上角分享
	 */
	onShareAppMessage() {

	}
})